﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PlatformUW.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlatformUW.EntityFramework.Mappings
{
    public class SensorMap : IEntityTypeConfiguration<SensorTable>
    {
        public void Configure(EntityTypeBuilder<SensorTable> builder)
        {
            builder.ToTable("Sensors");

            // 统一识别号
            builder.Property(sensors => sensors.Id)
                .IsRequired()
                .ValueGeneratedNever();

            // 传感器命名
            builder.Property(sensors => sensors.Name)
                .HasMaxLength(20)
                .IsRequired();
            builder.HasIndex(sensors => sensors.Name).IsUnique();

            // 传感器描述
            builder.Property(sensors => sensors.Description).HasMaxLength(100);

            builder.Property(sensors => sensors.PortCategory)
                .HasDefaultValue(PortCategory.TCP);

            builder.Property(sensors => sensors.Ip)
                .HasDefaultValue("127.0.0.1");

            builder.Property(sensors => sensors.SerialParams)
                .HasDefaultValue("N-8-1");

            builder.Property(sensors => sensors.optSupport21Cmd)
                .HasDefaultValue(true);

            builder.Property(sensors => sensors.optSplit3_4Cmd)
                .HasDefaultValue(false);

            builder.Property(sensors => sensors.Interval)
                .HasDefaultValue(100);
        }
    }
}
